/**
 * <copyright>
 *
 * Copyright (c) 2011 Zeligsoft (2009) Limited
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors: 
 *   Zeligsoft (2009) Limited - Initial API and implementation
 *
 * </copyright>
 *
 */
package org.omg.deployment.parts.forms;

import org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent;
import org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent;
import org.eclipse.emf.eef.runtime.api.parts.IFormPropertiesEditionPart;
import org.eclipse.emf.eef.runtime.impl.notify.PropertiesEditionEvent;
import org.eclipse.emf.eef.runtime.impl.parts.CompositePropertiesEditionPart;
import org.eclipse.emf.eef.runtime.ui.parts.PartComposer;
import org.eclipse.emf.eef.runtime.ui.parts.sequence.BindingCompositionSequence;
import org.eclipse.emf.eef.runtime.ui.parts.sequence.CompositionSequence;
import org.eclipse.emf.eef.runtime.ui.parts.sequence.CompositionStep;
import org.eclipse.emf.eef.runtime.ui.utils.EditingUtils;
import org.eclipse.emf.eef.runtime.ui.widgets.FormUtils;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.FocusAdapter;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.forms.widgets.Form;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.eclipse.ui.forms.widgets.Section;
import org.omg.deployment.parts.DeploymentViewsRepository;
import org.omg.deployment.parts.MonolithicDeploymentDescriptionPropertiesEditionPart;
import org.omg.deployment.providers.DeploymentMessages;


/**
 * @author Toby McClean; Zeligsoft (2009) Limited
 * @generated
 */
public class MonolithicDeploymentDescriptionPropertiesEditionPartForm extends CompositePropertiesEditionPart implements IFormPropertiesEditionPart, MonolithicDeploymentDescriptionPropertiesEditionPart {

	protected Text name;
	protected Text label;
	protected Text source;
	protected Text id;



	/**
	 * Default constructor
	 * @param editionComponent the {@link IPropertiesEditionComponent} that manage this part
	 * @generated
	 */
	public MonolithicDeploymentDescriptionPropertiesEditionPartForm(IPropertiesEditionComponent editionComponent) {
    super(editionComponent);
  }

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.eclipse.emf.eef.runtime.api.parts.IFormPropertiesEditionPart#
	 *  createFigure(org.eclipse.swt.widgets.Composite, org.eclipse.ui.forms.widgets.FormToolkit)
	 * @generated
	 */
	public Composite createFigure(final Composite parent, final FormToolkit widgetFactory) {
    ScrolledForm scrolledForm = widgetFactory.createScrolledForm(parent);
    Form form = scrolledForm.getForm();
    view = form.getBody();
    GridLayout layout = new GridLayout();
    layout.numColumns = 3;
    view.setLayout(layout);
    createControls(widgetFactory, view);
    return scrolledForm;
  }

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.eclipse.emf.eef.runtime.api.parts.IFormPropertiesEditionPart#
	 *  createControls(org.eclipse.ui.forms.widgets.FormToolkit, org.eclipse.swt.widgets.Composite)
	 * @generated
	 */
	public void createControls(final FormToolkit widgetFactory, Composite view) {
    CompositionSequence monolithicDeploymentDescriptionStep = new BindingCompositionSequence(propertiesEditionComponent);
    CompositionStep propertiesStep = monolithicDeploymentDescriptionStep.addStep(DeploymentViewsRepository.MonolithicDeploymentDescription.Properties.class);
    propertiesStep.addStep(DeploymentViewsRepository.MonolithicDeploymentDescription.Properties.name);
    propertiesStep.addStep(DeploymentViewsRepository.MonolithicDeploymentDescription.Properties.label);
    propertiesStep.addStep(DeploymentViewsRepository.MonolithicDeploymentDescription.Properties.source);
    propertiesStep.addStep(DeploymentViewsRepository.MonolithicDeploymentDescription.Properties.id);
    
    
    composer = new PartComposer(monolithicDeploymentDescriptionStep) {

      @Override
      public Composite addToPart(Composite parent, Object key) {
        if (key == DeploymentViewsRepository.MonolithicDeploymentDescription.Properties.class) {
          return createPropertiesGroup(widgetFactory, parent);
        }
        if (key == DeploymentViewsRepository.MonolithicDeploymentDescription.Properties.name) {
          return 		createNameText(widgetFactory, parent);
        }
        if (key == DeploymentViewsRepository.MonolithicDeploymentDescription.Properties.label) {
          return 		createLabelText(widgetFactory, parent);
        }
        if (key == DeploymentViewsRepository.MonolithicDeploymentDescription.Properties.source) {
          return 		createSourceText(widgetFactory, parent);
        }
        if (key == DeploymentViewsRepository.MonolithicDeploymentDescription.Properties.id) {
          return 		createIdText(widgetFactory, parent);
        }
        return parent;
      }
    };
    composer.compose(view);
  }
	/**
	 * @generated
	 */
	protected Composite createPropertiesGroup(FormToolkit widgetFactory, final Composite parent) {
    Section propertiesSection = widgetFactory.createSection(parent, Section.TITLE_BAR | Section.TWISTIE | Section.EXPANDED);
    propertiesSection.setText(DeploymentMessages.MonolithicDeploymentDescriptionPropertiesEditionPart_PropertiesGroupLabel);
    GridData propertiesSectionData = new GridData(GridData.FILL_HORIZONTAL);
    propertiesSectionData.horizontalSpan = 3;
    propertiesSection.setLayoutData(propertiesSectionData);
    Composite propertiesGroup = widgetFactory.createComposite(propertiesSection);
    GridLayout propertiesGroupLayout = new GridLayout();
    propertiesGroupLayout.numColumns = 3;
    propertiesGroup.setLayout(propertiesGroupLayout);
    propertiesSection.setClient(propertiesGroup);
    return propertiesGroup;
  }

	/**
	 * @generated
	 */
	
	protected Composite createNameText(FormToolkit widgetFactory, Composite parent) {
    FormUtils.createPartLabel(widgetFactory, parent, DeploymentMessages.MonolithicDeploymentDescriptionPropertiesEditionPart_NameLabel, propertiesEditionComponent.isRequired(DeploymentViewsRepository.MonolithicDeploymentDescription.Properties.name, DeploymentViewsRepository.FORM_KIND));
    name = widgetFactory.createText(parent, ""); //$NON-NLS-1$
    name.setEnabled(false);
    name.setToolTipText(DeploymentMessages.MonolithicDeploymentDescription_ReadOnly);
    name.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER);
    widgetFactory.paintBordersFor(parent);
    GridData nameData = new GridData(GridData.FILL_HORIZONTAL);
    name.setLayoutData(nameData);
    name.addFocusListener(new FocusAdapter() {
      /**
       * @see org.eclipse.swt.events.FocusAdapter#focusLost(org.eclipse.swt.events.FocusEvent)
       * @generated
       */
      @Override
      @SuppressWarnings("synthetic-access")
      public void focusLost(FocusEvent e) {
        if (propertiesEditionComponent != null)
          propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(MonolithicDeploymentDescriptionPropertiesEditionPartForm.this, DeploymentViewsRepository.MonolithicDeploymentDescription.Properties.name, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.SET, null, name.getText()));
      }
    });
    name.addKeyListener(new KeyAdapter() {
      /**
       * @see org.eclipse.swt.events.KeyAdapter#keyPressed(org.eclipse.swt.events.KeyEvent)
       * @generated
       */
      @Override
      @SuppressWarnings("synthetic-access")
      public void keyPressed(KeyEvent e) {
        if (e.character == SWT.CR) {
          if (propertiesEditionComponent != null)
            propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(MonolithicDeploymentDescriptionPropertiesEditionPartForm.this, DeploymentViewsRepository.MonolithicDeploymentDescription.Properties.name, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.SET, null, name.getText()));
        }
      }
    });
    EditingUtils.setID(name, DeploymentViewsRepository.MonolithicDeploymentDescription.Properties.name);
    EditingUtils.setEEFtype(name, "eef::Text"); //$NON-NLS-1$
    FormUtils.createHelpButton(widgetFactory, parent, propertiesEditionComponent.getHelpContent(DeploymentViewsRepository.MonolithicDeploymentDescription.Properties.name, DeploymentViewsRepository.FORM_KIND), null); //$NON-NLS-1$
    return parent;
  }

	/**
	 * @generated
	 */
	
	protected Composite createLabelText(FormToolkit widgetFactory, Composite parent) {
    FormUtils.createPartLabel(widgetFactory, parent, DeploymentMessages.MonolithicDeploymentDescriptionPropertiesEditionPart_LabelLabel, propertiesEditionComponent.isRequired(DeploymentViewsRepository.MonolithicDeploymentDescription.Properties.label, DeploymentViewsRepository.FORM_KIND));
    label = widgetFactory.createText(parent, ""); //$NON-NLS-1$
    label.setEnabled(false);
    label.setToolTipText(DeploymentMessages.MonolithicDeploymentDescription_ReadOnly);
    label.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER);
    widgetFactory.paintBordersFor(parent);
    GridData labelData = new GridData(GridData.FILL_HORIZONTAL);
    label.setLayoutData(labelData);
    label.addFocusListener(new FocusAdapter() {
      /**
       * @see org.eclipse.swt.events.FocusAdapter#focusLost(org.eclipse.swt.events.FocusEvent)
       * @generated
       */
      @Override
      @SuppressWarnings("synthetic-access")
      public void focusLost(FocusEvent e) {
        if (propertiesEditionComponent != null)
          propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(MonolithicDeploymentDescriptionPropertiesEditionPartForm.this, DeploymentViewsRepository.MonolithicDeploymentDescription.Properties.label, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.SET, null, label.getText()));
      }
    });
    label.addKeyListener(new KeyAdapter() {
      /**
       * @see org.eclipse.swt.events.KeyAdapter#keyPressed(org.eclipse.swt.events.KeyEvent)
       * @generated
       */
      @Override
      @SuppressWarnings("synthetic-access")
      public void keyPressed(KeyEvent e) {
        if (e.character == SWT.CR) {
          if (propertiesEditionComponent != null)
            propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(MonolithicDeploymentDescriptionPropertiesEditionPartForm.this, DeploymentViewsRepository.MonolithicDeploymentDescription.Properties.label, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.SET, null, label.getText()));
        }
      }
    });
    EditingUtils.setID(label, DeploymentViewsRepository.MonolithicDeploymentDescription.Properties.label);
    EditingUtils.setEEFtype(label, "eef::Text"); //$NON-NLS-1$
    FormUtils.createHelpButton(widgetFactory, parent, propertiesEditionComponent.getHelpContent(DeploymentViewsRepository.MonolithicDeploymentDescription.Properties.label, DeploymentViewsRepository.FORM_KIND), null); //$NON-NLS-1$
    return parent;
  }

	/**
	 * @generated
	 */
	
	protected Composite createSourceText(FormToolkit widgetFactory, Composite parent) {
    FormUtils.createPartLabel(widgetFactory, parent, DeploymentMessages.MonolithicDeploymentDescriptionPropertiesEditionPart_SourceLabel, propertiesEditionComponent.isRequired(DeploymentViewsRepository.MonolithicDeploymentDescription.Properties.source, DeploymentViewsRepository.FORM_KIND));
    source = widgetFactory.createText(parent, ""); //$NON-NLS-1$
    source.setEnabled(false);
    source.setToolTipText(DeploymentMessages.MonolithicDeploymentDescription_ReadOnly);
    source.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER);
    widgetFactory.paintBordersFor(parent);
    GridData sourceData = new GridData(GridData.FILL_HORIZONTAL);
    source.setLayoutData(sourceData);
    source.addFocusListener(new FocusAdapter() {
      /**
       * @see org.eclipse.swt.events.FocusAdapter#focusLost(org.eclipse.swt.events.FocusEvent)
       * @generated
       */
      @Override
      @SuppressWarnings("synthetic-access")
      public void focusLost(FocusEvent e) {
        if (propertiesEditionComponent != null)
          propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(MonolithicDeploymentDescriptionPropertiesEditionPartForm.this, DeploymentViewsRepository.MonolithicDeploymentDescription.Properties.source, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.SET, null, source.getText()));
      }
    });
    source.addKeyListener(new KeyAdapter() {
      /**
       * @see org.eclipse.swt.events.KeyAdapter#keyPressed(org.eclipse.swt.events.KeyEvent)
       * @generated
       */
      @Override
      @SuppressWarnings("synthetic-access")
      public void keyPressed(KeyEvent e) {
        if (e.character == SWT.CR) {
          if (propertiesEditionComponent != null)
            propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(MonolithicDeploymentDescriptionPropertiesEditionPartForm.this, DeploymentViewsRepository.MonolithicDeploymentDescription.Properties.source, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.SET, null, source.getText()));
        }
      }
    });
    EditingUtils.setID(source, DeploymentViewsRepository.MonolithicDeploymentDescription.Properties.source);
    EditingUtils.setEEFtype(source, "eef::Text"); //$NON-NLS-1$
    FormUtils.createHelpButton(widgetFactory, parent, propertiesEditionComponent.getHelpContent(DeploymentViewsRepository.MonolithicDeploymentDescription.Properties.source, DeploymentViewsRepository.FORM_KIND), null); //$NON-NLS-1$
    return parent;
  }

	/**
	 * @generated
	 */
	
	protected Composite createIdText(FormToolkit widgetFactory, Composite parent) {
    FormUtils.createPartLabel(widgetFactory, parent, DeploymentMessages.MonolithicDeploymentDescriptionPropertiesEditionPart_IdLabel, propertiesEditionComponent.isRequired(DeploymentViewsRepository.MonolithicDeploymentDescription.Properties.id, DeploymentViewsRepository.FORM_KIND));
    id = widgetFactory.createText(parent, ""); //$NON-NLS-1$
    id.setEnabled(false);
    id.setToolTipText(DeploymentMessages.MonolithicDeploymentDescription_ReadOnly);
    id.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER);
    widgetFactory.paintBordersFor(parent);
    GridData idData = new GridData(GridData.FILL_HORIZONTAL);
    id.setLayoutData(idData);
    id.addFocusListener(new FocusAdapter() {
      /**
       * @see org.eclipse.swt.events.FocusAdapter#focusLost(org.eclipse.swt.events.FocusEvent)
       * @generated
       */
      @Override
      @SuppressWarnings("synthetic-access")
      public void focusLost(FocusEvent e) {
        if (propertiesEditionComponent != null)
          propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(MonolithicDeploymentDescriptionPropertiesEditionPartForm.this, DeploymentViewsRepository.MonolithicDeploymentDescription.Properties.id, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.SET, null, id.getText()));
      }
    });
    id.addKeyListener(new KeyAdapter() {
      /**
       * @see org.eclipse.swt.events.KeyAdapter#keyPressed(org.eclipse.swt.events.KeyEvent)
       * @generated
       */
      @Override
      @SuppressWarnings("synthetic-access")
      public void keyPressed(KeyEvent e) {
        if (e.character == SWT.CR) {
          if (propertiesEditionComponent != null)
            propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(MonolithicDeploymentDescriptionPropertiesEditionPartForm.this, DeploymentViewsRepository.MonolithicDeploymentDescription.Properties.id, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.SET, null, id.getText()));
        }
      }
    });
    EditingUtils.setID(id, DeploymentViewsRepository.MonolithicDeploymentDescription.Properties.id);
    EditingUtils.setEEFtype(id, "eef::Text"); //$NON-NLS-1$
    FormUtils.createHelpButton(widgetFactory, parent, propertiesEditionComponent.getHelpContent(DeploymentViewsRepository.MonolithicDeploymentDescription.Properties.id, DeploymentViewsRepository.FORM_KIND), null); //$NON-NLS-1$
    return parent;
  }



	/**
	 * {@inheritDoc}
	 * 
	 * @see org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionListener#firePropertiesChanged(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)
	 * @generated
	 */
	public void firePropertiesChanged(IPropertiesEditionEvent event) {
  }

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.omg.deployment.parts.MonolithicDeploymentDescriptionPropertiesEditionPart#getName()
	 * @generated
	 */
	public String getName() {
    return name.getText();
  }

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.omg.deployment.parts.MonolithicDeploymentDescriptionPropertiesEditionPart#setName(String newValue)
	 * @generated
	 */
	public void setName(String newValue) {
    if (newValue != null) {
      name.setText(newValue);
    } else {
      name.setText(""); //$NON-NLS-1$
    }
  }


	/**
	 * {@inheritDoc}
	 * 
	 * @see org.omg.deployment.parts.MonolithicDeploymentDescriptionPropertiesEditionPart#getLabel()
	 * @generated
	 */
	public String getLabel() {
    return label.getText();
  }

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.omg.deployment.parts.MonolithicDeploymentDescriptionPropertiesEditionPart#setLabel(String newValue)
	 * @generated
	 */
	public void setLabel(String newValue) {
    if (newValue != null) {
      label.setText(newValue);
    } else {
      label.setText(""); //$NON-NLS-1$
    }
  }


	/**
	 * {@inheritDoc}
	 * 
	 * @see org.omg.deployment.parts.MonolithicDeploymentDescriptionPropertiesEditionPart#getSource()
	 * @generated
	 */
	public String getSource() {
    return source.getText();
  }

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.omg.deployment.parts.MonolithicDeploymentDescriptionPropertiesEditionPart#setSource(String newValue)
	 * @generated
	 */
	public void setSource(String newValue) {
    if (newValue != null) {
      source.setText(newValue);
    } else {
      source.setText(""); //$NON-NLS-1$
    }
  }


	/**
	 * {@inheritDoc}
	 * 
	 * @see org.omg.deployment.parts.MonolithicDeploymentDescriptionPropertiesEditionPart#getId()
	 * @generated
	 */
	public String getId() {
    return id.getText();
  }

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.omg.deployment.parts.MonolithicDeploymentDescriptionPropertiesEditionPart#setId(String newValue)
	 * @generated
	 */
	public void setId(String newValue) {
    if (newValue != null) {
      id.setText(newValue);
    } else {
      id.setText(""); //$NON-NLS-1$
    }
  }




	/**
	 * {@inheritDoc}
	 *
	 * @see org.eclipse.emf.eef.runtime.api.parts.IPropertiesEditionPart#getTitle()
	 * @generated
	 */
	public String getTitle() {
    return DeploymentMessages.MonolithicDeploymentDescription_Part_Title;
  }



}
